package com.eatme.leetcode.problems;

import java.util.TreeSet;

/**
 * 804. 唯一摩尔斯密码词 - unique-morse-code-words
 */
class Solution804 {
    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        TreeSet<String> set = new TreeSet<>();
        for (String word: words) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < word.length(); i++)
                sb.append(codes[word.charAt(i)-'a']);
            set.add(sb.toString());
        }
        return set.size();
    }

    public static void main(String[] args) {
        String []  words = {"gin", "zen", "gig", "msg"};
        System.out.println(new Solution804().uniqueMorseRepresentations(words));
    }
}